<template>
	<scroll-view class="page-content" :scroll-top="scrollTop" scroll-y="true" @scrolltolower="loadmore()">
		<view class="page-body">
			<template v-if="datalist && datalist.length > 0 ">
				<block v-for="(item,index) in datalist" :key="index">
					<view class="body-box" @click="tonearby(item.id)">
						<view class="box-tit">{{i18n.activationCode.jihuoma}}：{{item.code}}</view>
						<view class="icons-sel">{{i18n.activationCode.jihuo}}
							<text class="icon-tb icons icon-gengduo"></text>
						</view>
					</view>
				</block>
				<!-- 上拉加载 -->
				<view class="det-con-more">
					<load-more :loadmore="load_more1"></load-more>
				</view>
			</template>
			<!--无数据-->
			<empty v-else no-full type="noData"></empty>
		</view>
	</scroll-view>
</template>

<script>
	import {
		mapGetters,
		mapActions
	} from "vuex";
	import store from '@/store';
	import {
		getDeviceCodeLists,
	} from '@/common/api.js';
	import loadMore from '@/components/uni-load-more/load-more.vue'
	export default {
		components: {
			loadMore
		},
		data() {
			return {
				scrollTop: 0,
				noData: false,
				load_more1: '', //下拉加载文字
				load_sta: false, //是否是加载状态
				datalist: [{
						value: 'asdasdasd',
						statu: true,
					},
					{
						value: 'asdasdasd',
						statu: true,
					}
				],
				formData:{
					page:1,
					limt:10
				}
			}
		},
		computed: {
			i18n() {
				return this.$t('message');
			}
		},
		onShow() {
			// 导航栏多语言
			uni.setNavigationBarTitle({
				title: this.i18n.tabBar.activationCode
			});
			this.getdata(this.formData);
		},
		onLoad(option) {

		},
		methods: {
			//下拉加载
			loadmore() {
				console.log('下拉加载');
				let _self = this;
				_self.load_sta = true;
				_self.formData.page++;
				_self.getdata(_self.formData);
			},
			getdata(formData) {
				getDeviceCodeLists(formData).then(res => {
					console.log(333, res)
					if (res.code === 2000) {
						let datalist = res.data;
						if (this.load_sta) {
							if (datalist && datalist.length < 10) {
								this.load_more1 = '没有更多了';
								this.datalist = this.datalist.concat(datalist);
							} else {
								this.load_more1 = '加载中...';
									this.datalist = this.datalist.concat(datalist);
							}
						} else {
							if (datalist && datalist.length < 10) {
								this.load_more1 = '没有更多了';
								this.datalist = datalist;
							} else {
								this.load_more1 = '加载中...';
									this.datalist = datalist;
							}
						}
					}
				})
			},
			tonearby(id) {
				uni.navigateTo({
					url: "/pages/user/nearby?code_id=" + id
				})
			}
		},
		onPullDownRefresh() {
			console.log('refresh');
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		}
	}
</script>

<style lang="scss">
	.weixuanzhong {
		width: 36rpx;
		height: 36rpx;
		background: #393939;
		border: 1px solid #646464;
		border-radius: 50%;
	}
	
	.det-con-more {
		display: flex;
		justify-content: center;
		align-items: center;
		margin-bottom: 10rpx;
		color: #999;
		font-size: 24rpx;
	}

	.page-content {
		width: 100vw;
		height: 100%;
		background: $uni-bg-color;
		color: $font-color-w;
		.page-body{
			padding: $page-row-spacing;
			height: 100%;
		}
	}

	.body-box {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		background: $uni-bg-box-color;
		box-shadow: 0rpx 2rpx 9rpx 0rpx rgba(0, 0, 0, 0.44);
		border-radius: 20rpx;
		margin-bottom: 30rpx;
		padding: 30rpx 40rpx;
		color: #FFFFFF;

		.box-tit {
			display: flex;
			font-size: 32rpx;
			font-weight: 500;
			color: #FFFFFF;
		}

		.icons-sel {
			font-size: 28rpx;
			font-weight: 400;
			color: #D50000;

			.icon-tb {
				color: $font-color-w;
				margin-left: 20rpx;
			}
		}
	}
</style>
